package main.cn.dao.impl;

import main.cn.dao.OrderDao;
import main.cn.pojo.Order;

import java.util.List;


public class OrderDaoImpl extends BaseDao implements OrderDao {
    @Override
    public int addOrder(Order order) {
        String sql = "insert into orders (id,userid,orderstate,money,start_address,end_address,time_delivery,time_guess) " +
                "values(?,?,?,?,?,?,?,?)";
        return update(sql,order.getId(),order.getUserid(),order.getOrderstate(),order.getMoney(),
                order.getStart_address(),order.getEnd_address(),order.getTime_delivery(),order.getTime_guess());
    }

    @Override
    public int deleteOrder(int id) {
        String sql = "delete from orders where id = ?";
        return update(sql,id);
    }

    @Override
    public int updateOrder(Order order) {
        String sql = "update orders set userid=?,orderstate=?,money=?,start_address=?,end_address=?," +
                "time_delivery=?,time_guess=? where id=?";
        return update(sql,order.getUserid(),order.getOrderstate(),order.getMoney(),
                order.getStart_address(),order.getEnd_address(),order.getTime_delivery(),order.getTime_guess(),order.getId());
    }

    @Override
    public Order queryOrderById(int id) {
        String sql = "select id,userid,orderstate,money,start_address,end_address,time_delivery,time_guess from orders where id = ?";
        return queryForOne(Order.class,sql,id);
    }

    @Override
    public List<Order> queryOrders() {
        String sql = "select id,userid,orderstate,money,start_address,end_address,time_delivery,time_guess from orders";
        return queryForList(Order.class,sql);
    }
}
